package com.bw.module_splash

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.CountDownTimer
import android.widget.ImageView
import android.widget.TextView
import androidx.databinding.DataBindingUtil
import com.alibaba.android.arouter.launcher.ARouter
import com.bumptech.glide.Glide
import com.bw.lib_base.path.RouterPath
import com.bw.module_splash.databinding.ActivitySplashBinding

class SplashActivity : AppCompatActivity() {
    private lateinit var mCountDownTimer: CountDownTimer
    private lateinit var binding: ActivitySplashBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash)
        binding = DataBindingUtil.setContentView(this, R.layout.activity_splash)

        Glide.with(this).load(R.drawable.pic_background).into(binding.ivBg)

        //5秒倒时
        mCountDownTimer=object : CountDownTimer(5000,1000){
            override fun onTick(millisUntilFinished: Long) {
                binding.countDownText.text="${millisUntilFinished / 1000}秒跳过"
            }

            override fun onFinish() {
                this@SplashActivity.jumpToLoginPage()
            }
        }

        //启动倒计时
        mCountDownTimer.start()

        //点击跳过跳转到主页
        binding.countDownText.setOnClickListener {
            ARouter.getInstance().build(RouterPath.PATH_MAIN_ACTIVITY).navigation()
            mCountDownTimer.cancel()
            this@SplashActivity.finish()
        }
    }

    private fun jumpToLoginPage(){
        ARouter.getInstance().build(RouterPath.PATH_MAIN_ACTIVITY).navigation()
        this@SplashActivity.finish()
    }
}